package com.demo.accessibility.ui

import android.os.Bundle
import android.text.Layout
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.addTextChangedListener
import com.blankj.utilcode.util.ConvertUtils
import com.demo.accessibility.R
import com.demo.accessibility.widgets.IconLabelTextView

/// @Author: ligang
/// @Date: 2024/6/1
/// @Description: class SvgaTaillightDemo {
class SvgaTaillightDemo : AppCompatActivity() {
    lateinit var mTv: TextView
    lateinit var mTips: TextView
    lateinit var mImageView: ImageView
    lateinit var mIconLabelTextView: IconLabelTextView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_svga_taillight_demo)

        mTv = findViewById(R.id.tv_content)
        mTips = findViewById(R.id.tv_tips)
        mImageView = findViewById(R.id.image)
        mIconLabelTextView = findViewById(R.id.productVariation)
        findViewById<EditText>(R.id.et).addTextChangedListener {
            mTv.text = it.toString()
            mIconLabelTextView.text = it.toString()
//            if (TextUtils.isEmpty(mTv.text)) {
//                mImageView.visibility = View.GONE
//            } else {
//                mImageView.visibility = View.VISIBLE
//                val x = getTextLastCharX()
//                mImageView.x = x
//                mTv.measure(0, 0)
//                val y = mTv.measuredHeight.toFloat()
//                mImageView.y = y
//                Log.e("===========", "x : $x ,y : $y")
//            }
        }

        mIconLabelTextView.setIcon(
            getDrawable(R.mipmap.weideng),
            ConvertUtils.dp2px(4f),
            0,
            0,
            iconWidth = ConvertUtils.dp2px(26f),
            iconHeight = ConvertUtils.dp2px(26f)
        )

        mIconLabelTextView.mCallback = {left, top, right, bottom->
            mImageView.layoutParams?.let {
                if(it is MarginLayoutParams) {
                    it.leftMargin = left
                    it.topMargin = top
                    mImageView.layoutParams = it
                }
            }
//            mImageView.x = left.toFloat()
//            mImageView.y = top.toFloat()

            mTips.text = "primaryHorizontal=x : $left ,y : $top"
        }
    }
}